#!/bin/bash
#by 1903王栋 1964050326

function add_users_groups()
{
	groupadd team1 
	groupadd team2 
	groupadd manager
	useradd -g manager s1964050326
	(echo "123456" && echo "123456") | passwd s1964050326
	for i in  `seq 1000001 1000020`
	do
 		if(( $i < 1000011 ));then
			useradd -g team1 s$i
			(echo "ss$i" && echo "ss$i") | passwd s$i
	 	else
			useradd -g team2 s$i
			(echo "ss$i" && echo "ss$i") | passwd s$i
		fi
 		if [ $? -ne 0 ];then
			echo "Run failed"
			exit
		else
			echo -e "\033[36mCreating a successful\033[0m"
		fi
	done
}

function del_users_groups()
{
	for i in  `seq 1000001 1000020`
	do
		userdel -r s$i
	done
		userdel -r s1964050326
		groupdel manager
		groupdel team1
		groupdel team2
		echo -e "\033[36mSuccessfully delete\033[0m"
}

function Menu()
{
	echo -e "\033[32mPlease enter the service you want \033[0m"	
	echo "1)add_users_groups"
	echo "2)del_users_groups"
	echo "3)Exit"	
}

if [[ $uid -ne 0 || $UID -ne 0 ]];then
	echo  -e "\033[36mPlease Run the $0 under root\033[0m"
	exit
fi


echo -e "\033[32mPlease enter the service you want \033[0m"

PS3="select your will exec Menu:"

select j in "add_users_groups" "del_users_groups" "Exit"

do

 case $j in
	add_users_groups )
	add_users_groups
	Menu
	;;

	del_users_groups )
	del_users_groups
	Menu
	;;

	Exit )
	exit
	;;

        * )
	echo -e "\033[32mUsage: {$0 add_users|del_users|Exit}\033[0m"
 esac

done

